package com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.dto.TElectricityCostRecordsDayDto;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.dto.SaveTElectricityCostRecordsDayFormDataDto;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.vo.TElectricityCostRecordsDayVo;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.vo.TElectricityCostRecordsDayListVo;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.dto.TElectricityCostRecordsDayListDto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import com.xjrsoft.module.customerTwo.EMP.t_water_cost_records_day.enums.MonthEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.entity.TElectricityCostRecordsDay;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.vo.TElectricityCostRecordsDayVo;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_day.service.ITElectricityCostRecordsDayService;

/**
 *  控制器
 *
 * @author dongxinhang
 * @since 2023-07-24
 */
@RestController
@AllArgsConstructor
@RequestMapping("/electricity_cost_records_day")
@Api(value = "每天电费记录", tags = "每天电费记录接口")
public class TElectricityCostRecordsDayController {


	private final ITElectricityCostRecordsDayService tElectricityCostRecordsDayService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入tElectricityCostRecordsDay")
	@SaCheckPermission(value = {"electricity_cost_records_day:view", "electricity_cost_records_day:modify"}, mode = SaMode.OR)
	public Response<TElectricityCostRecordsDayVo> getFormData(@PathVariable String id) {
		// 主表数据
		TElectricityCostRecordsDay tElectricityCostRecordsDay = tElectricityCostRecordsDayService.getById(id);
		TElectricityCostRecordsDayVo tElectricityCostRecordsDayVo = BeanUtil.copy(tElectricityCostRecordsDay, TElectricityCostRecordsDayVo.class);
		return Response.ok(tElectricityCostRecordsDayVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tElectricityCostRecordsDay")
		public Response<PageOutput<TElectricityCostRecordsDayListVo>> getPageList(TElectricityCostRecordsDayListDto listDto) {
		String month = MonthEnum.getCodeByValue(listDto.getMonth());
		if(StringUtils.isNotBlank(month)){
			listDto.setMonth(month);
		}
		IPage<TElectricityCostRecordsDay> page = tElectricityCostRecordsDayService.getPageList(listDto);
		List<TElectricityCostRecordsDayListVo> records = BeanUtil.copyList(page.getRecords(), TElectricityCostRecordsDayListVo.class);
			// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		// 转换列表数据
		DataTransUtil.transListShowData(records);
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

}
